home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr11
/
powerb5.zip
/
P5DOS009.TIP
< prev
next >
Wrap
Text File
|
1993-06-01
|
2KB
|
37 lines
I've discovered a way to manipulate text strings in batch
files, thanks to a little-known aspect of the DOS FOR
command: If a string in the parenthesized portion of FOR's
parameters is preceded by a slash, DOS splits it into two
strings: the first character, and the remainder of the
string. To see this trick in action, enter the command FOR
%Y IN (/1234) DO ECHO %Y at the DOS prompt. DOS first echoes
'1', then '234'. Enclosed are two batch files that show how
you can use this hidden talent. The first, LENGTH.BAT,
returns as the environment variable LNGTH the length of a
word stored in another variable called STRING. The second,
OFFLEFT.BAT, deletes the first N characters of STRING, where
N and STRING are both environment variables. Use SET to
create STRING and N before running these batch files and to
see the results.
David Graczyk
Amherst, New York
Editor's Note: Before I saw this tip, I didn't know that
DOS's batch language had even rudimentary string-handling
capabilities, but this technique opens the door to all sorts
of ingenious tricks. For example, you could create a menu
that allows you to select several options, each represented
by a letter or digit, at one time by typing them in sequence
on the command line. The two sample batch files LENGTH.BAT
and OFFLEFT.BAT are both in the P5DOS directory of your
PowerBase *.* Volume 5 diskette.
Title: Fantastic FOR
Category: DOS
Issue Date: September, 1992
Editor: Brett Glass
Supplementary Files: P5DOS\LENGTH.BAT, P5DOS\OFFLEFT.BAT
Filename: P5DOS009.TIP